﻿//创建时间: 2010-10-11
//创建作者: 李 城
//功能说明: 字符替换 添加 修改
//最后修改: 2010-10-11
using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using TRPOP.Common;
using TRPOP.CMS.Web.UI;


using TRPOP.CMS.Business;
using TRPOP.CMS.Model;
using System.Collections;

namespace TRPOP.CMS.Web.Admin
{
    public partial class WordReplace_save : BaseAdmin
    {

        #region 当前页面权限验证
        protected override void SubPageInit()
        {
            base.m_SubPagePermission = Plugin.PermissionKeys.PermissionEnum.SystemManage_KeysReplace;
        }
        #endregion


        #region 页面变量
        protected bool m_IsAdd = true;
        protected int m_id = 0;
        protected int m_cid = 0;
        protected string m_Title = "";
        WordReplaceInfo mWordReplaceInfo = new WordReplaceInfo();
        WordReplaceManage mWordReplaceManage = new WordReplaceManage();
        #endregion

        #region 页面事件
        protected void Page_Load(object sender, EventArgs e)
        {
            m_cid = RequestHelper.RequestInt("cid");
            if (!IsPostBack)
            {
                BindData();
                LoadBase();
            }
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string strMSG = "名称、待替换文字或替换后的值";
            if (!PageAssist.CheckForm(txtName, ref strMSG) || !PageAssist.CheckForm(txtOldValue, ref strMSG) || !PageAssist.CheckForm(txtNewValue, ref strMSG))
            {
                Alert(strMSG);
                return;
            }

            int.TryParse(GetRequestViewState("id"), out m_id);
            mWordReplaceInfo = mWordReplaceManage.GetInfoById(m_id);
            if (mWordReplaceInfo == null)
            {
                mWordReplaceInfo = new WordReplaceInfo();
            }
            mWordReplaceInfo.WordReplaceName = txtName.Text.RemoveHtml();
            mWordReplaceInfo.Type = rbtType.SelectedValue.ToInt();
            mWordReplaceInfo.OldValue = txtOldValue.Text;
            mWordReplaceInfo.NewValue = txtNewValue.Text;
            mWordReplaceInfo.Nodeids = txtNodeids.Text;
            mWordReplaceInfo.AddTime = base.GetAdminAddTime;
            mWordReplaceInfo.AddUserId = base.mUserBaseInfo.UserBaseId;
            if (m_id > 0)
            {
                base.SaveLog(Plugin.LogKeys.OperObject.TemplateOper, Plugin.LogKeys.OperResult.AddSubmit);
            }
            else
            {
                base.SaveLog(Plugin.LogKeys.OperObject.TemplateOper, Plugin.LogKeys.OperResult.EditSubmit);
            }
            SubmitAlertAndThisNewLocation(mWordReplaceManage.Save(mWordReplaceInfo), "WordReplace_list.aspx");
           // SubmitAlertAndParReset(mWordReplaceManage.Save(mWordReplaceInfo));
        }
        #endregion

        #region 页面方法

        public void LoadBase()
        {
            int.TryParse(InitRequestViewState("id"), out m_id);
            mWordReplaceInfo = mWordReplaceManage.GetInfoById(m_id);
            if (mWordReplaceInfo != null)
            {
                m_IsAdd = false;
                m_Title = mWordReplaceInfo.WordReplaceName;
                txtName.Text = mWordReplaceInfo.WordReplaceName;
                rbtType.SelectedValue = mWordReplaceInfo.Type.ToString();
                txtOldValue.Text = mWordReplaceInfo.OldValue;
                txtNewValue.Text = mWordReplaceInfo.NewValue;
                txtNodeids.Text = mWordReplaceInfo.Nodeids;
                m_Title = rbtType.SelectedItem.Text;
            }
        }
        public void BindData()
        {
            rbtType.DataSource = PageAssist.GetAllWordReplaceType(SystemInfoHelper.getSystemInfo().AdminFolderName);
            rbtType.DataBind();
            if (m_cid > 0)
            {
                rbtType.SelectedValue = m_cid.ToString();
                m_Title = rbtType.SelectedItem.Text;
            }
            else
                rbtType.SelectedIndex = 0;
        }
        #endregion
    }
}
